package cn.smbms.interceptor;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import cn.smbms.pojo.User;
import cn.smbms.tools.Constants;

public class SysInterceptor  extends HandlerInterceptorAdapter{
	private static final Logger logger=Logger.getLogger(SysInterceptor.class);
	
	public boolean preHandle(HttpServletRequest request,HttpServletResponse response,Object handler){
		logger.debug("SysInterceptor-==========preHandle");
		HttpSession session=request.getSession();
		User user=(User) session.getAttribute(Constants.USER_SESSION);
		if (null==user) {
			try {
				response.sendRedirect(request.getContextPath()+"/401.jsp");
			} catch (IOException e) {
				e.printStackTrace();
			}
			return false;
		}
		return true;
	}
}
